import temporal.util 
import temporal.preprocess
# import classification as cls
import numpy as np
import librosa
import pickle


def quick_predict_class(test_audio):
    """
    如果给音频地址也行，就把下面第一行取消注释即可。
    :param test_audio: np.array。如果要给地址，就把第一行取消注释。
    :return: 四个分类器给出的预测结果。
    """
    # test_audio, sampling_rate = librosa.load(path="test5.wav", sr=44100, mono=True)
    print(test_audio.shape)
    X_0 = temporal.preprocess.single_audio(test_audio, T=197)

    # 加载模型
    svm_model = pickle.load(open("./temporal/svm.dat", "rb"))
    RDFT_model = pickle.load(open("./temporal/RDFT.dat", "rb"))
    NB_model = pickle.load(open("./temporal/NB.dat", "rb"))
    AdaB_model = pickle.load(open("./temporal/AdaB.dat", "rb"))

    # 预测
    SVC_pred = svm_model.predict(X_0)
    RDFT_pred = RDFT_model.predict(X_0)
    NB_pred = NB_model.predict(X_0)
    AdaB_pred = AdaB_model.predict(X_0)

    # SVC_pred = cls.SVC(X, y, X_0)
    # RDFT_pred = cls.RDFT(X, y, X_0)
    # NB_pred = cls.NB(X, y, X_0)
    # AdaB_pred = cls.AdaB(X, y, X_0)

    print("SVC_predict: %d\nRDFT_predict: %d\nNB_predict: %d\nAdaB_predict: %d" % (
    SVC_pred, RDFT_pred, NB_pred, AdaB_pred))
    return SVC_pred, RDFT_pred, NB_pred, AdaB_pred
